﻿using RStudio.UIFramwork.Editor.Utils;
using RStudio.UIFramwork.Utils;
using UnityEditor;


namespace RStudio.UIFramwork.Editor
{
    [CanEditMultipleObjects]
    [CustomEditor(typeof(UIBase), true)]
    public class EditUIBase : UnityEditor.Editor
    {
        private UIBase m_UIBase;

        public void OnEnable()
        {
            m_UIBase = target as UIBase;
        }

        public override void OnInspectorGUI()
        {
            DoDraw();
        }


        public void DoDraw()
        {
            bool isGet = UIAssetUtil.IsUIDetailAttached(m_UIBase.GetType(), out UIDetailAttribute output);
            string description = isGet ? output.Description : "缺失";
            string assetLink = isGet ? output.AssetLink : "缺失";
            EditorGUILayout.LabelField($"页面描述：{description}", EditorStyles.boldLabel);
            EditorGUILayout.LabelField($"资产路径：{assetLink}", EditorStyles.boldLabel);


            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical("box");
            {
                EditorGUILayout.LabelField("附加功能区", EditorStyles.boldLabel);
            }
            EditorGUILayout.EndVertical();
            {
                EditorGUILayout.BeginHorizontal("box");
                {
                    EditUIComponentUtil.UnitToggle("区域关闭", ref m_UIBase.UseAreaQuit, m_UIBase);
                    EditUIComponentUtil.UnitToggle("区域阻挡", ref m_UIBase.UseBlock, m_UIBase);
                    EditUIComponentUtil.UnitToggle("区域遮罩", ref m_UIBase.UseMask, m_UIBase);
                    EditUIComponentUtil.UnitToggle("区域拖拽", ref m_UIBase.UseDrag, m_UIBase);
                }
                EditorGUILayout.EndHorizontal();
            }


            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical("box");
            {
                EditorGUILayout.LabelField("布局调整区", EditorStyles.boldLabel);
            }
            EditorGUILayout.EndVertical();
            {
                EditorGUILayout.BeginHorizontal("box");
                {
                    EditUIComponentUtil.UnitToggle("四周型", ref m_UIBase.UseQuardRato, m_UIBase);
                    EditUIComponentUtil.UnitToggle("居中型", ref m_UIBase.UseCentral, m_UIBase);
                }
                EditorGUILayout.EndHorizontal();
            }


            EditorGUILayout.Space();



            EditorGUILayout.BeginVertical("box");
            {
                EditorGUILayout.LabelField("核心逻辑区", EditorStyles.boldLabel);
            }
            EditorGUILayout.EndVertical();
            {
                EditorGUILayout.BeginHorizontal("box");
                {
                    EditUIComponentUtil.UnitToggle("唯一实例", ref m_UIBase.UseAsSingle, m_UIBase);

                    EditUIComponentUtil.UnitToggle("关闭前页", ref m_UIBase.UseClosePrevious, m_UIBase);
                    EditUIComponentUtil.UnitToggle("允许关闭", ref m_UIBase.CanBeClosed, m_UIBase);
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal("box");
                {
                    EditUIComponentUtil.UnitToggle("启用回退", ref m_UIBase.CanBeRecord, m_UIBase);
                    EditUIComponentUtil.UnitSlider("权重数据", ref m_UIBase.Weight, 0, 100, m_UIBase);
                }
                EditorGUILayout.EndHorizontal();
            }
           


            EditorGUILayout.Space();

            base.OnInspectorGUI();
        }
    }
}
